package com.appspot.aliga;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;


public class Match {
	
	private static final SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");

	private Long matchID;
	private String team1Name;
	private String team2Name;
	private int team1Result;
	private int team2Result;
	private Date matchDate;
	private int leagueID;
	private int gameDay;
	
	public static Match fromJSON(JSONObject jo) {
		Match match = new Match();
		try {
			match.setMatchID(jo.getLong("matchID"));
			match.setTeam1Name(jo.getString("team1Name"));
			match.setTeam2Name(jo.getString("team2Name"));
			match.setTeam1Result(jo.getInt("team1Result"));
			match.setTeam2Result(jo.getInt("team2Result"));
			match.setLeagueID(jo.getInt("leagueID"));
			match.setGameDay(jo.getInt("gameDay"));
			try {
			match.setMatchDate(df.parse(jo.getString("matchDate")));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
		} catch (JSONException e) {
			//
		}
		return match;
	}
	
	@Override
	public String toString() {
		return team1Name + " " + team1Result + ":" + team2Result + " " + team2Name;
	}

	public Long getMatchID() {
		return matchID;
	}

	public void setMatchID(Long matchID) {
		this.matchID = matchID;
	}

	public String getTeam1Name() {
		return team1Name;
	}

	public void setTeam1Name(String team1Name) {
		this.team1Name = team1Name;
	}

	public String getTeam2Name() {
		return team2Name;
	}

	public void setTeam2Name(String team2Name) {
		this.team2Name = team2Name;
	}

	public int getTeam1Result() {
		return team1Result;
	}

	public void setTeam1Result(int team1Result) {
		this.team1Result = team1Result;
	}

	public int getTeam2Result() {
		return team2Result;
	}

	public void setTeam2Result(int team2Result) {
		this.team2Result = team2Result;
	}

	public Date getMatchDate() {
		return matchDate;
	}

	public void setMatchDate(Date matchDate) {
		this.matchDate = matchDate;
	}

	public int getLeagueID() {
		return leagueID;
	}

	public void setLeagueID(int leagueID) {
		this.leagueID = leagueID;
	}

	public int getGameDay() {
		return gameDay;
	}

	public void setGameDay(int gameDay) {
		this.gameDay = gameDay;
	}

	

}
